using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using NUnit.Framework;
using Universe.JRun;

namespace Universe.CrossIO.Test
{
    [TestFixture]
    public class TestCultures
    {
        [Test]
        public void Test()
        {
            JRunner jr = new JRunner("cldctest.Main_GetCultureList", MyEnvironment.ClassPath);
            JResponse y = jr.Run();
            DateTime dt = new DateTime(2009,1,1,23,24,25);
            using(StringReader reader = new StringReader(y.Output))
            {
                while(true)
                {
                    string row = reader.ReadLine();
                    if (row == null)
                        break;

                    string[] arr = row.Split(new char[] {':'});
                    string name = arr[0];
                    string englishName = arr[1];
                    string jFormat = MyEnvironment.HexDecode(arr[2]);
                    string jValue = MyEnvironment.HexDecode(arr[3]);
                    // Trace.WriteLine("Try " + row);
                    try
                    {
                        if (name != "ar-sa" && name != "dv-mv" && name != "ns-za")
                        {
                            CultureInfo culture = CultureInfo.GetCultureInfo(name);
                            // Assert.AreEqual(culture.EnglishName, englishName, "Culture {0}", name);
                            string nValue = dt.ToString(jFormat, culture.DateTimeFormat);
                            Trace.WriteLine(name + ": '" + jValue + "'");
                            Trace.WriteLine(
                                (name == "" ? "" : new string(' ', name.Length))
                                + "  '" + nValue + "'");

                            bool areEquals = StringComparer.Create(culture, true).Compare(nValue, jValue) == 0;
                            Assert.IsTrue(areEquals);
                        }
                    }
                    catch(ArgumentException ex)
                    {
                        Trace.WriteLine(
                            string.Format(
                            "Culture '{0}' [{1}] is not supported: {2}",
                            englishName,
                            name,
                            ex.Message));
                    }
                }
            }


        }

    }
}
